/**
 * 系统主页JS
 * @author Assassin
 */

function gotoEditSelfPage(){
	parent.main.layer.open({
        type: 2,
        title: '编辑个人信息',
        area: ['400px', '230px'],
        shade: 0.5,
        closeBtn: 0,
        shadeClose: true,
        content: shiro.baseUrl + 'gotoEditSelf'
    });
}

//角色切换
function selectRole(){
	var roleId=$("#role").val();
	// 提交登录
    shiro.ajax({
        url: 'roleChange',
        data:{'roleId':roleId},
        success: function(data) {
            if(data.result == 0) {
                window.parent.location.href=shiro.baseUrl +'main';
            } else {
                layer.msg(data.message, {icon: 5,time: 1000});
            }
        }
    });
}

// 执行修改个人信息
function executeEditSelf() {
    //表单验证
    var realName = $.trim($('#realName').val());
    if(shiro.util.isEmpty(realName)) {
        layer.tips('姓名不能为空', '#realName');
        return false;
    }
    var telphone = $.trim($('#telphone').val());
    if(shiro.util.isEmpty(telphone)) {
        layer.tips('手机号码不能为空', '#telphone');
        return false;
    }
    var email = $.trim($('#email').val());
    // 提交登录
    shiro.ajax({
        url: 'editSelf',
        data:$('#editSelfForm').serialize(),
        success: function(data) {
            if(data.result == 0) {
                layer.msg(data.message, {icon: 1,time: 1000}, function() {
                    parent.layer.closeAll();
                });
            } else {
                layer.msg(data.message, {icon: 5,time: 1000});
                $('#realName').val('');
            }
        }
    });
    return false;
}

// 进入修改密码页面
function gotoEditPswdPage() {
	parent.main.layer.open({
        type: 2,
        title: '修改密码',
        area: ['400px', '230px'],
        shade: 0.5,
        closeBtn: 0,
        shadeClose: true,
        content: shiro.baseUrl + 'gotoEditPswd'
    });
}

// 执行密码修改
function executeEditSeltPswd() {
    //表单验证
    var oldPswd = $.trim($('#oldPswd').val());
    if(shiro.util.isEmpty(oldPswd)) {
        layer.tips('原密码不能为空', '#oldPswd');
        return false;
    }
    var newPswd = $.trim($('#newPswd').val());
    if(shiro.util.isEmpty(newPswd)) {
        layer.tips('新密码不能为空', '#newPswd');
        return false;
    }
    var rpswd = $('#rpswd').val();
    if(shiro.util.isEmpty(rpswd)) {
        layer.tips('确认密码不能为空', '#rpswd');
        return false;
    }
    if(newPswd != rpswd) {
        layer.tips('两次输入密码不一致', '#rpswd');
        return false;
    }
    // 提交修改
    shiro.ajax({
        url: 'editSeltPswd',
        data:$('#editSeltPswdForm').serialize(),
        success: function(data) {
            if(data.result == 0) {
                layer.msg(data.message, {icon: 1,time: 1000}, function() {
                    parent.layer.closeAll();
                });
            } else {
                layer.msg(data.message, {icon: 5,time: 1000});
                $('#oldPswd').val('');
            }
        }
    });
    return false;
}

// 退出登录
function executeLogout() {
	parent.main.layer.msg('确定退出登录？', {
        time: 0,
        btn: ['确定', '取消'],
        yes: function(index){
            layer.close(index);
            window.parent.location.href = shiro.baseUrl + "logout";
        }
    });
}

$(document).ready(function(){
	var roleIds=$("#roleIds").val();
	$("#role").val(roleIds);
});